package com.sskj.qiangjin.http;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.common.http.WebSocketObserver;
import com.sskj.lib.Constans;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.bean.UserBean;
import com.sskj.lib.bean.UserData;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.qiangjin.bean.BackUserBean;
import com.sskj.qiangjin.bean.BankerHistoryBean;
import com.sskj.qiangjin.bean.BankerHistoryListBean;
import com.sskj.qiangjin.bean.BankersMainBean;
import com.sskj.qiangjin.bean.BillRecordBean;
import com.sskj.qiangjin.bean.CommonBean;
import com.sskj.qiangjin.bean.ImgUrlBean;
import com.sskj.qiangjin.bean.LinkBean;
import com.sskj.qiangjin.bean.MyGuessBean;
import com.sskj.qiangjin.bean.NewNoticeBean;
import com.sskj.qiangjin.bean.NoticeBean;
import com.sskj.qiangjin.bean.NoticeMsgBean;
import com.sskj.qiangjin.bean.OpenAwardBean;
import com.sskj.qiangjin.bean.RankBean;
import com.sskj.qiangjin.bean.RechargeBean;
import com.sskj.qiangjin.bean.RechargeListBean;
import com.sskj.qiangjin.bean.RollMsg;
import com.sskj.qiangjin.bean.RollPointsBean;
import com.sskj.qiangjin.bean.ShowPayBean;
import com.sskj.qiangjin.bean.SocketSendBean;
import com.sskj.qiangjin.bean.ToRechargeBean;
import com.sskj.qiangjin.bean.TxDataBean;
import com.sskj.qiangjin.bean.UpdataBean;
import com.sskj.qiangjin.bean.VcerifyBean;
import com.sskj.qiangjin.bean.WalletBean;
import com.sskj.qiangjin.bean.WithDrawBean;
import com.sskj.qiangjin.bean.WithDrawLimitBean;

import java.io.File;
import java.util.List;

import okhttp3.WebSocket;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService implements IHttpService {
    /**
     * 登录
     *
     * @param pswd    密码
     * @param account 账号
     * @return
     */
    @Override
    public PostRequest<HttpData<BackUserBean>> login(String account, String pswd) {
        return OkGo.<HttpData<BackUserBean>>post(HttpConfig.BASE_URL + HttpConfig.LOGIN)
                .params("opwd", pswd)
                .params("mobile", account);
    }


    @Override
    public PostRequest<HttpData> uploadImg(File file) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.UPLOAD_FILE)
                .params("headimg", file);
    }

    @Override
    public PostRequest<HttpData<ImgUrlBean>> uploadPhoto(String url) {
        return OkGo.<HttpData<ImgUrlBean>>post(HttpConfig.BASE_URL + HttpConfig.UPLOAD_IMG)
                .params("upic", url);
    }

    @Override
    public PostRequest<HttpData> register(String mobile, String opwd, String code, String tjuser, String realname) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.REGISTER)
                .params("mobile", mobile)
                .params("opwd", opwd)
                .params("opwd1", opwd)
                .params("code", code)
                .params("tjuser", tjuser)
                .params("realname", realname);
    }

    @Override
    public PostRequest<HttpData> pwdForget(String code, String mobile, String opwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.PWD_FORGET)
                .params("code", code)
                .params("mobile", mobile)
                .params("opwd", opwd)
                .params("opwd1", opwd);
    }

    @Override
    public PostRequest<HttpData> pwdReset(String oldpwd, String opwd, String opwd1) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.PWD_RESET)
                .params("oldpwd", oldpwd)
                .params("opwd", opwd)
                .params("opwd1", opwd1);
    }

    @Override
    public PostRequest<HttpData<CommonBean>> getCommonData() {
        return OkGo.<HttpData<CommonBean>>post(HttpConfig.BASE_URL + HttpConfig.COMMON_DATA);
    }

    @Override
    public PostRequest<HttpData<LinkBean>> getLinkData() {
        return OkGo.<HttpData<LinkBean>>post(HttpConfig.BASE_URL + HttpConfig.LINK_DATA);
    }

    @Override
    public PostRequest<HttpData<UserBean>> userInfo(String money_type) {
        return OkGo.<HttpData<UserBean>>post(HttpConfig.BASE_URL + HttpConfig.USER_INFO)
                .params("money_type", money_type);
    }

    @Override
    public GetRequest<HttpData<TxDataBean>> getTxData() {
        return OkGo.<HttpData<TxDataBean>>get(HttpConfig.BASE_URL + HttpConfig.GET_TX_DATA);
    }

    @Override
    public PostRequest<HttpData<PageBean<NoticeBean>>> noticeList(int page, int size) {
        return OkGo.<HttpData<PageBean<NoticeBean>>>post(HttpConfig.BASE_URL + HttpConfig.NOTICE_LIST)
                .params("page", page)
                .params("size", size);
    }

    @Override
    public PostRequest<HttpData<NewNoticeBean>> isHaveNoticeList(int page, int size) {
        return OkGo.<HttpData<NewNoticeBean>>post(HttpConfig.BASE_URL + HttpConfig.NOTICE_LIST)
                .params("page", page)
                .params("size", size);
    }

    @Override
    public PostRequest<HttpData<PageBean<WithDrawBean>>> getWithDrawList(int type, int page, int size) {
        return OkGo.<HttpData<PageBean<WithDrawBean>>>post(HttpConfig.BASE_URL + HttpConfig.WITH_DRAW_LIST)
                .params("pid", type)
                .params("page", page)
                .params("size", size);
    }

    @Override
    public PostRequest<HttpData<NoticeMsgBean>> noticeMsg(String id) {
        return OkGo.<HttpData<NoticeMsgBean>>post(HttpConfig.BASE_URL + HttpConfig.NOTICE_MSG)
                .params("id", id);
    }

    @Override
    public PostRequest<HttpData<PageBean<RankBean>>> rankList(String money_type, String type, int page, int size) {
        return OkGo.<HttpData<PageBean<RankBean>>>post(HttpConfig.BASE_URL + HttpConfig.RANK_LIST)
                .params("money_type", money_type)
                .params("type", type)
                .params("page", page)
                .params("size", size);
    }

    @Override
    public PostRequest<HttpData> updataTel(String code, String tpwd, String new_mobile) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.UPDATA_TEL)
                .params("code", code)
                .params("tpwd", tpwd)
                .params("new_mobile", new_mobile);
    }

    @Override
    public GetRequest<HttpData> sendCode(String mobile, String type) {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.SEND_SMS)
                .params("mobile", mobile)
                .params("type", type);
    }

    @Override
    public GetRequest<HttpData<WithDrawLimitBean>> withDrawLimit() {
        return OkGo.<HttpData<WithDrawLimitBean>>get(HttpConfig.BASE_URL + HttpConfig.WITH_DRAW_LIMIT);
    }

    @Override
    public PostRequest<HttpData<RechargeBean>> getRecharge() {
        return OkGo.<HttpData<RechargeBean>>post(HttpConfig.BASE_URL + HttpConfig.RECHAGRE_URL);
    }


    @Override
    public PostRequest<HttpData<PageBean<BillRecordBean>>> billRecordList(String money_type, String start_time, String end_time, int page, int size) {
        return OkGo.<HttpData<PageBean<BillRecordBean>>>post(HttpConfig.BASE_URL + HttpConfig.BILL_LIST)
                .params("money_type", money_type)
                .params("start_time", start_time)
                .params("end_time", end_time)
                .params("page", page)
                .params("size", size);
    }

    @Override
    public PostRequest<HttpData<PageBean<OpenAwardBean>>> openAwardList(String account, int page, int size) {
        return OkGo.<HttpData<PageBean<OpenAwardBean>>>post(HttpConfig.BASE_URL + HttpConfig.OPEN_AWARD)
                .params("account", account)
                .params("page", page)
                .params("size", size);
    }

    @Override
    public PostRequest<HttpData<PageBean<MyGuessBean>>> myGuessList(int page, int size) {
        return OkGo.<HttpData<PageBean<MyGuessBean>>>post(HttpConfig.BASE_URL + HttpConfig.MY_GUESS)
                .params("page", page)
                .params("size", size);
    }

    @Override
    public PostRequest<HttpData> setPayPwd(String tpwd, String account, String code, String mobile) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.PAY_PWD)
                .params("tpwd", tpwd)
                .params("tpwd1", tpwd)
                .params("account", account)
                .params("code", code)
                .params("mobile", mobile);
    }

    @Override
    public PostRequest<HttpData<BankersMainBean>> bankerPoolMain(String money_type) {
        return OkGo.<HttpData<BankersMainBean>>post(HttpConfig.BASE_URL + HttpConfig.BANKER_POLL_MAIN)
                .params("money_type", money_type);
    }

    @Override
    public PostRequest<HttpData<BankerHistoryListBean>> bankerPoolHistory(String money_type, int page, int size) {
        return OkGo.<HttpData<BankerHistoryListBean>>post(HttpConfig.BASE_URL + HttpConfig.BANKER_POLL_HISTORY)
                .params("money_type", money_type)
                .params("page", page)
                .params("size", size);
    }

    @Override
    public PostRequest<HttpData<PageBean<WalletBean>>> walletAddressList() {
        return OkGo.<HttpData<PageBean<WalletBean>>>post(HttpConfig.BASE_URL + HttpConfig.WALLET_ADDRESS);
    }

    @Override
    public PostRequest<HttpData> addWallet(String address, String remark) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.WALLET_ADD)
                .params("address", address)
                .params("remark", remark);
    }

    @Override
    public PostRequest<HttpData> deleteWallet(String id) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.WALLET_DELETE)
                .params("id", id);
    }

    @Override
    public PostRequest<HttpData> bankerInOut(String type, String money) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.BANKER_IN_OUT)
                .params("type", type)
                .params("money", money);
    }

    @Override
    public PostRequest<HttpData> normalBet(String type, String money, String escape_beishu) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.NOEMAL_BET)
                .params("type", type)
                .params("money", money)
                .params("escape_beishu", escape_beishu);
    }

    @Override
    public PostRequest<HttpData> normalRun() {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.NOEMAL_RUN);
    }


    @Override
    public PostRequest<HttpData<PageBean<RechargeListBean>>> rechargeList(int pid, int page, int size) {
        return OkGo.<HttpData<PageBean<RechargeListBean>>>post(HttpConfig.BASE_URL + HttpConfig.RECHAGRE_LIST)
                .params("pid", pid)
                .params("page", page)
                .params("size", size);
    }

    @Override
    public PostRequest<HttpData<PageBean<VcerifyBean>>> vcerify(String hash, String num) {
        return OkGo.<HttpData<PageBean<VcerifyBean>>>post(HttpConfig.BASE_URL + HttpConfig.VERIFY)
                .params("hash", hash)
                .params("num", num);
    }

    @Override
    public PostRequest<HttpData> withDraw(String code, String address, String price, String tpwd, String pid) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.WITH_DRAW)
                .params("code", code)
                .params("address", address)
                .params("price", price)
                .params("tpwd", tpwd)
                .params("pay_type", pid);
    }

    @Override
    public PostRequest<HttpData> withDrawCoin(String code, String price, String tpwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.COIN_WITH_DRAW)
                .params("code", code)
                .params("price", price)
                .params("tpwd", tpwd);
    }

    @Override
    public PostRequest<HttpData<RollMsg>> rollMsg() {
        return OkGo.<HttpData<RollMsg>>post(HttpConfig.BASE_URL + HttpConfig.ROLL_MSG);
    }

    @Override
    public PostRequest<HttpData<UpdataBean>> updata(String version) {
        return OkGo.<HttpData<UpdataBean>>post(HttpConfig.BASE_URL + HttpConfig.UPDATA)
                .params("version", version)
                .params("type", 1);
    }

    @Override
    public PostRequest<HttpData<RollPointsBean>> rollPoints() {
        return OkGo.<HttpData<RollPointsBean>>post(HttpConfig.BASE_URL + HttpConfig.ROLL_POINT);
    }

    @Override
    public GetRequest<HttpData> getExchange() {
        return OkGo.<HttpData>get(HttpConfig.BASE_URL + HttpConfig.EXCHANGE);
    }

    @Override
    public PostRequest<HttpData<ToRechargeBean>> getRechargeUrl(String price) {
        return OkGo.<HttpData<ToRechargeBean>>post(HttpConfig.BASE_URL + HttpConfig.CHONGZHI)
                .params("pay_type", 1)
                .params("orderamount", price);
    }

    @Override
    public PostRequest<HttpData<ToRechargeBean>> getCoinRechargeUrl(String price, int type) {
        return OkGo.<HttpData<ToRechargeBean>>post(HttpConfig.BASE_URL + HttpConfig.COIN_CHONGZHI)
                .params("pid", 3)
                .params("pay_type", type)
                .params("orderamount", price);
    }

    @Override
    public PostRequest<HttpData> addPayWay(String address, String realname, String bankcard, String branch, String bank) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADD_PAY_WAY)
                .params("address", address)
                .params("realname", realname)
                .params("bankcard", bankcard)
                .params("branch", branch)
                .params("bank", bank);
    }

    @Override
    public PostRequest<HttpData<ShowPayBean>> showPay() {
        return OkGo.<HttpData<ShowPayBean>>post(HttpConfig.BASE_URL + HttpConfig.SHOW_PAY);
    }

    @Override
    public WebSocketObserver pushBloomType(String type) {
        return new WebSocketObserver(HttpConfig.WS_BASE_URL) {
            @Override
            public void onOpen(WebSocket webSocket, okhttp3.Response response) {
                webSocket.send(new Gson().toJson(new SocketSendBean(Constans.DEFAULT_BIBI_COIN)));
            }
        };
    }
}